// 引入pdf解析工具
// import * as pdfjs from 'pdfjs-dist'
// import * as pdfjsWorker from 'pdfjs-dist/build/pdf.worker.entry'
// pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker
import * as pdfjsLib from 'pdfjs-dist';
// import * as pdfjsWorker from 'pdfjs-dist/build/pdf.worker.entry.js'

pdfjsLib.GlobalWorkerOptions.workerSrc = 'js/pdf/pdf.worker.min.js';

// 引入图片压缩工具
import * as imageConversion from 'image-conversion'

export const uploadMixins = {
  data() {
    return {
      isWeb: true,
      uploadIndex: 1,
      theatredKey: '',
      theatreKey: '',
      selectAllTheatred: false,
      showTheatre: false,
      // theatredList: [],
      ebookLimit: 100000,
      previewLimit: 100000,
      showUpload: true,
      showPhoneUpload: true,
      showImg: false,
      uploadFileStatus: false,
      uploadingNum: 1,
      pngBlob: [],
      pngIndex: 0,
      showFileDialog: false,
      modelValue: false,
      uploadingFiles: [],//选择的文件列表
      uploadingRes: [],//无作用
      scDialogFileData: {
        isDIY: false,
        isDefense: true,
        isUploadedFile: false,//是否已上传
        isPreview: false,
        uploadResponse: '',
        uploadFiles: '',//选择的文件对象pdf
        imgFiles: [],//待上传的ebook文件列表
        imgPreviewFiles: [],//待上传preview文件列表
        page: 3,
        compression: true,
        file: '',
        previewFile: '',
        newImg: ''
      },
      scDialogData: {
        isUploaded: false,//是否已上传
        thumbnailUrl: '',
        isDefense: true,
        newImg: '',
        compression: true,
        posterImg: '',
        uploadResponse: '',
        uploadFiles: '',
        files: ''
      },
      fileAction: 'fileType',
      action: '#',//this.$API.upload.creator_uploadFile
    }
  },
  methods: {
    sortImg(){
      let sortArr = this.scDialogFileData.imgFiles;
      if(this.scDialogFileData.isPreview)sortArr = this.scDialogFileData.imgPreviewFiles
      if(!sortArr.length)return
      sortArr = sortArr.sort((a,b)=>{return parseInt(a.key)-parseInt(b.key)>-1?1:-1})
    },
    async upload(type = ''){
      let data = new FormData();
      data.file = this.scDialogData.uploadFiles;
      for (const key in this.scDialogData.uploadFiles) {
        data.append(key, this.scDialogData.uploadFiles[key]);
      }
      if(this.scDialogData.uploadResponse.path){
        this.isSaveing = true
        // const awsApiObj = config.awsApiObj;
        this.$API.upload.awsUploadFile.put(this.scDialogData.uploadResponse.path,data.file,{'Content-Type': data.file.type}).then(res => {
          console.log(res)
          this.isSaveing = false;
          this.openUpload()
          if(type == 'activity') {
            if(this.isWeb) {
              this.form.imageFileId = this.scDialogData.uploadResponse.fileId;
              this.form.image = this.scDialogData.newImg;
              this.showUpload = false
            } else {
              this.form.phoneImageId = this.scDialogData.uploadResponse.fileId;
              this.form.phoneImage = this.scDialogData.newImg;
              this.showPhoneUpload = false
            }
          } else {
            this.form.thumbnailId = this.scDialogData.uploadResponse.fileId;
            this.form.thumbnailUrl = this.scDialogData.newImg;
            this.showUpload = false
          }
          this.$message.success(this.$t('table_data.operasucc'))
        }).catch(err => {
          this.uploadFileStatus = false
          console.log(err)
          // param.onError(err)
        })
        // console.log('path：',apiObj)
      }
    },
    async uploadFiles(param,index){
      console.log('开始上传...',param)
      const fileType = {
        image: 1,
        audio: 3,
        eBook: 4,
        other: 9,
        video: 2
      }
      const fileCategory = {
        artwork: 1,
        attachment: 5,
        avatar: 3,
        bgImage: 4,
        certificate: 6,
        certificateThumbnail: 7,
        thumbnail: 2
      }
      let data = {};
      for(let i=0;i<param.type.split('/').length;i++){
        if(['pdf','txt','xlsx'].includes(param.type.split('/')[i])){
          data.type = 4
        }else if(['jpg','jpeg','png','gif','webp','tiff','bmp','svg'].includes(param.type.split('/')[i])){
          data.type = 1
        }else {
          data.type = fileType[(param.type.split('/')[0])]?fileType[(param.type.split('/')[0])]:9;
        }
      }
      data.file = param;
      data.category = fileCategory.artwork;
      
      let params = `?filename=${data.file.name}&category=${data.category}&type=${data.type}`;
      this.$API.upload.setFile.get(params).then(res=>{
        if(res.path){
          let fileData = new FormData();
          fileData.file = param;
          for (const key in param) {
            fileData.append(key, param[key]);
          }
  
          // const awsApiObj = config.awsApiObj;
          this.$API.upload.awsUploadFile.put(res.path,fileData.file,{'Content-Type': fileData.file.type}).then(response => {
            console.log(response)
            // if(!this.scDialogFileData.isPreview)this.form.fileId = res.fileId
            if(index==-1){
              this.form.fileId = res.fileId;
              this.scDialogFileData.file = 'ebookFile.pdf';
              console.log('fileId',this.form.fileId);
              this.scDialogData.isUploaded=true;
              return
            }
            if(++index>this.pngBlob.length){
              this.uploadFileStatus=false;
              this.$message.success(this.$t('table_data.operasucc'))
              if(!this.scDialogFileData.isPreview)this.setFileId();
              // if(this.showImg&&!this.scDialogFileData.isPreview)this.form.fileId = res.fileId;
              if(this.scDialogFileData.isPreview){
                this.scDialogFileData.isUploadedFile=true;
              }else{
                this.scDialogData.isUploaded=true;
              }
              this.openUploadFile();
              this.uploadIndex = 1
              this.showCoutinueBtn = false
              console.log(`上传s3成功`,this.form)
            }else{
              this.uploadIndex = index;
              this.showCoutinueBtn = false
              this.turnBlob(index)
              this.uploadingNum = index
            }
            if(this.scDialogFileData.isPreview){
              this.form.previewFiles.push(res.fileId)
              this.scDialogFileData.previewFile = 'previewFile.pdf'
            }else{
              this.form.ebookFiles.push(res.fileId)
              this.scDialogFileData.file = 'ebookFile.pdf'
            }
            console.log('upload success',this.form)
          }).catch(err => {
            this.uploadFileStatus = false
            this.showCoutinueBtn = true;
            console.log('上传aws断开',err)
            // param.onError(err)
          })
          // console.log('path：',apiObj)
        }
      }).catch(e=>{
        this.uploadFileStatus = false
        this.showCoutinueBtn = true;
        console.log('上传断开',e)
      })
    },
    // 获取本地file
    readFile(filePath) {
      // 创建一个新的xhr对象
      let xhr = null
      if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest()
      } else {
        // eslint-disable-next-line
        xhr = new ActiveXObject('Microsoft.XMLHTTP')
      }
      const okStatus = document.location.protocol === 'file' ? 0 : 200
      xhr.open('GET', filePath, false)
      xhr.overrideMimeType('application/pdf;charset=utf-8')
      xhr.send(null)
      return xhr.status === okStatus ? xhr.responseText : null
    },
    setFileId(){
      let createFileId = this.readFile('file.pdf')
      this.createFileId = new File([createFileId], 'testfile.pdf', {type: 'application/pdf'})
      this.uploadFiles(this.createFileId,-1)
    },
    turnBlob(i,type){
      if(this.showCoutinueBtn)i=this.uploadIndex;
      if(type=='click'&&(this.scDialogFileData.isPreview&&this.form.previewFiles&&this.form.previewFiles.length||!this.scDialogFileData.isPreview&&this.form.ebookFiles&&this.form.ebookFiles.length)){
        this.openUploadFile()
        return
      }
      this.uploadFileStatus = true;
      if(this.showImg){
        this.uploadFiles(this.scDialogFileData.isPreview?this.scDialogFileData.imgPreviewFiles[i-1].file.raw:this.scDialogFileData.imgFiles[i-1].file.raw,i)
        return
      }
      const canvas = document.getElementById('pdf_canvas_'+i);
      canvas.toBlob((blob)=>{
        console.log('压缩前1',blob);
        if(this.scDialogFileData.compression){
          this.pdfCompression(blob).then(res=>{
            let file = new File([res], this.pngBlob[i-1], {type: 'image/jpeg'})
            this.uploadFiles(file,i)
            console.log('压缩后1',res,file);
          })
        }else{
          let file = new File([blob], this.pngBlob[i-1], {type: 'image/jpeg'})
          this.uploadFiles(file,i)
          console.log('不压缩1');
        }
      },'image/jpeg',1)
    },
    inputPage(e){
      if(e<1)return false
    },
    // jpg 处理
    handlePNG(file,index){
      // let pngfile = file;
      let reader = new FileReader();
      reader.addEventListener('load', (e) => {
        let base64 = e.target.result;
        // let blob = new Blob([base64], { type: file.type });
        if(this.scDialogFileData.isPreview){
          this.scDialogFileData.imgPreviewFiles[index] = {}
          this.scDialogFileData.imgPreviewFiles[index].img = base64
          this.scDialogFileData.imgPreviewFiles[index].key = index
          this.scDialogFileData.imgPreviewFiles[index].file = {raw: this.uploadingFiles[index].raw}
          if(!this.scDialogFileData.compression&&!this.scDialogFileData.isDefense){
            if(this.uploadingFiles.length-1>index){
              this.handleEachImg(++index)
            }else{
              this.uploadFileStatus=false
              this.scDialogFileData.previewFile = 'previewFile.pdf'
            }
            this.pngBlob[index] = base64
            return
          }
          this.$nextTick(()=>{
            this.setWatermark(this.$refs['uImg'+index][0],this.scDialogFileData.isDefense?'img/water.png':'img/mark.png').then(canvas=>{
              this.scDialogFileData.imgPreviewFiles[index].img = [canvas.toDataURL('image/jpeg')]
              if(this.scDialogFileData.compression){
                canvas.toBlob((blob)=>{
                  console.log('压缩前1',blob);
                  let name = new Date().getTime()+'.jpg';
                  this.pdfCompression(blob).then(res=>{
                    console.log('压缩后1',res);
                    let file = new File([res], name, {type: 'image/jpeg'})
                    this.scDialogFileData.imgPreviewFiles[index].file = {raw: file}
                    if(this.uploadingFiles.length-1>index){
                      this.handleEachImg(++index)
                    }else{
                      this.uploadFileStatus=false
                      this.scDialogFileData.previewFile = 'previewFile.pdf'
                    }
                  })
                },'image/jpeg',1)
              }else{
                this.scDialogFileData.imgPreviewFiles[index].file = {raw: this.uploadingFiles[index].raw}
                if(this.uploadingFiles.length-1>index){
                  this.handleEachImg(++index)
                }else{
                  this.uploadFileStatus=false
                  this.scDialogFileData.previewFile = 'previewFile.pdf'
                }
              }
            })
          })
        }else{
          this.scDialogFileData.imgFiles[index] = {}
          this.scDialogFileData.imgFiles[index].img = base64
          this.scDialogFileData.imgFiles[index].key = index
          if(this.scDialogFileData.compression){
            this.$nextTick(()=>{
              this.setWatermark(this.$refs['uImg'+index][0],'img/mark.png').then(canvas=>{
                this.scDialogFileData.imgFiles[index].img = canvas.toDataURL('image/jpeg')
                canvas.toBlob((blob)=>{
                  let name = new Date().getTime()+'.jpg';
                  console.log('压缩前1',blob);
                  this.pdfCompression(blob).then(res=>{
                    console.log('压缩后1',res);
                    let file = new File([res], name, {type: 'image/jpeg'})
                    this.scDialogFileData.imgFiles[index].file = {raw: file}
                    if(this.uploadingFiles.length-1>index){
                      this.handleEachImg(++index)
                    }else{
                      this.uploadFileStatus=false
                      this.scDialogFileData.file = 'ebookFile.pdf'
                    }
                  })
                },'image/jpeg',1)
              })
            })
          }else{
            this.scDialogFileData.imgFiles[index].file = {raw: this.uploadingFiles[index].raw}
            if(this.uploadingFiles.length-1>index){
              this.handleEachImg(++index)
            }else{
              this.uploadFileStatus=false
              this.scDialogFileData.file = 'ebookFile.pdf'
            }
          }
        }
        this.pngBlob[index] = base64
      })
      reader.readAsDataURL(file)

    },
    // pdf turn jpg
    handlePDF(){
      let file = this.scDialogFileData.uploadFiles.raw;
      if (file) {
        const reader = new FileReader();
        reader.onload = async (e) => {
          try {
            const pdfData = new Uint8Array(e.target.result);
            const pdf = await pdfjsLib.getDocument({ data: pdfData }).promise;
            this.scDialogFileData.imgFiles = [];
            var pageNum = pdf.numPages;
            if(this.scDialogFileData.isPreview&&this.scDialogFileData.page&&pageNum>=this.scDialogFileData.page&&this.scDialogFileData.isDIY)pageNum=this.scDialogFileData.page
  
            for (let i = 1; i <= pageNum; i++) {
              let one = 'pdf';
              if(this.scDialogFileData.isPreview){
                this.scDialogFileData.imgPreviewFiles.push({img:one})
              }else{
                this.scDialogFileData.imgFiles.push({img:one})
              }
              
              await this.previewPNG(1,pageNum,pdf)
            }
          } catch(e) {
            this.uploadFileStatus = false;
            this.$message.error(e)
          }
        };
        reader.readAsArrayBuffer(file);
      }

      // let file = this.scDialogFileData.uploadFiles.raw;
      // // let pdfName = file.name.substring(0, file.name.lastIndexOf("."));
      // var reader = new FileReader();
      // reader.readAsDataURL(file); //将文件读取为 DataURL
      // reader.onload = ()=> { //文件读取成功完成时触发
      //   try{
      //     const loadingTask = pdfjs.getDocument(reader.result)
      //     loadingTask.promise.then((pdf) => {
      //       var pageNum = pdf.numPages;
      //       if(this.scDialogFileData.isPreview&&this.scDialogFileData.page&&pageNum>=this.scDialogFileData.page&&this.scDialogFileData.isDIY)pageNum=this.scDialogFileData.page
      //       console.log("页数:" + pageNum,pdf);
      //       // 准备图片
      //       for (let i = 1; i <= pageNum; i++) {
      //         let one = 'pdf';
      //         if(this.scDialogFileData.isPreview){
      //           this.scDialogFileData.imgPreviewFiles.push({img:one})
      //         }else{
      //           this.scDialogFileData.imgFiles.push({img:one})
      //         }
      //       }
      //       this.previewPNG(1,pageNum,pdf)
      //     }).catch(e=>{
      //       this.uploadFileStatus = false;
      //       this.$message.error(e)
      //     })
      //   }catch(e){
      //     this.uploadFileStatus = false;
      //     this.$message.error(e)
      //   }
      // }
    },
    previewPNG(i,pageNum,pdf){
      pdf.getPage(i).then(async (page) => {
        const canvas = document.getElementById('pdf_canvas_'+i);
        const ctx = canvas.getContext('2d')
        const viewport = page.getViewport({ scale: 3 })
        // 画布大小,默认值是width:300px,height:150px
        canvas.height = viewport.height;
        canvas.width = viewport.width;
        // 画布的dom大小, 设置移动端,宽度设置铺满整个屏幕
        //const clientWidth = document.body.clientWidth;
        const destWidth = 398;
        canvas.style.width = destWidth + 'px';
        // 根据pdf每页的宽高比例设置canvas的高度
        canvas.style.height = destWidth * (viewport.height / viewport.width) + 'px';
        await page.render({
          canvasContext: ctx,
          viewport,
        }).promise;
        if(this.scDialogFileData.isPreview&&i<=pageNum){
          await this.pdfWaterMark(canvas)
        }else if(this.scDialogFileData.isPreview){
          return
        }
        this.pngBlob.push(new Date().getTime()+'.jpg')
        if(i<pageNum){
          this.previewPNG(++i,pageNum,pdf)
        }else{
          this.uploadFileStatus = false;
          console.log('完成解析')
        }
      }).catch(e=>{
        this.uploadFileStatus = false;
        console.log('解析异常',e)
      })
    },
    // pdf图片压缩
    pdfCompression(blob){
      return new Promise((resolve) => {
        imageConversion.compress(blob,0.9).then(res=>{
          resolve(res)
        }).catch(e=>{
            console.log('错误',e)
        })
      })
    },
    // pdf加水印
    pdfWaterMark(element){
      if(!this.scDialogFileData.isDefense){
        return
      }
      return new Promise((resolve) => {
        const water = new Image()
        water.src = 'img/water.png'
        let canvas = element
        let ctx = canvas.getContext("2d");
        water.onload = ()=>{
          ctx.drawImage(water, 0, 0, canvas.width, canvas.height)
          resolve(true)
        }
      })
    },
    // 压缩图片
    getBlob(){
      this.scDialogData.newImg = this.scDialogData.files.tempFile
      this.$nextTick(()=>{
        if(!this.scDialogData.compression){
          if(this.scDialogData.isDefense){
            this.setWatermark(this.$refs.wm).then(canvas=>{
              this.scDialogData.newImg = canvas.toDataURL(this.scDialogData.uploadFiles.type);
              canvas.toBlob((blob)=>{
                console.log('水印',new File([blob], this.scDialogData.uploadFiles.name, {type: this.scDialogData.uploadFiles.type}))
                this.scDialogData.uploadFiles = new File([blob], this.scDialogData.uploadFiles.name, {type: this.scDialogData.uploadFiles.type})
                this.scDialogData.thumbnailUrl = canvas.toDataURL(this.scDialogData.uploadFiles.type)
              },this.scDialogData.uploadFiles.type,1)
            })
          }
          return
        }
        this.$refs.cropper.getCropFile(file=>{
          this.scDialogData.newImg = URL.createObjectURL(file)
          this.scDialogData.uploadFiles = file
          console.log('压缩',file)
          if(this.scDialogData.isDefense){
            this.setWatermark(this.$refs.wm).then(canvas=>{
              this.scDialogData.newImg = canvas.toDataURL(this.scDialogData.uploadFiles.type);
              canvas.toBlob((blob)=>{
                console.log('水印',new File([blob], this.scDialogData.uploadFiles.name, {type: this.scDialogData.uploadFiles.type}))
                this.scDialogData.uploadFiles = new File([blob], this.scDialogData.uploadFiles.name, {type: this.scDialogData.uploadFiles.type})
                this.scDialogData.thumbnailUrl = canvas.toDataURL(this.scDialogData.uploadFiles.type)
              },this.scDialogData.uploadFiles.type,1)
            })
          }
        }, this.scDialogData.uploadFiles.name, 'image/jpeg')
      })
    },
    // 加水印
    setWatermark(ref,imgUrl='img/water.png'){
      return new Promise((resolve) => {
        const water = new Image()
        water.src = imgUrl;
        let imageCon = ref;
        let canvas = document.createElement("canvas");
        let ctx = canvas.getContext("2d");
        water.onload = ()=>{
          canvas.width = imageCon.width
          canvas.height = imageCon.height
          ctx.drawImage(imageCon, 0, 0, imageCon.width, imageCon.height);
          ctx.drawImage(water, 0, 0, imageCon.width, imageCon.height)
          resolve(canvas)
        }
      })

    },
    openUpload(isWeb = true, showDefense = true){
      this.modelValue = !this.modelValue;
      this.isSaveing = false;
      if(this.modelValue) {
        this.isWeb = isWeb;
      }
      if(!this.modelValue) {
        if(this.scDialogData.thumbnailUrl) {
          // this.form.imageFileId = "";
          // this.form.image = "";
          // this.form.phoneImageId = "";
          // this.form.phoneImage = "";
          // this.form.coverPicture = "";
          // this.form.coverPictureId = "";
          this.scDialogData.thumbnailUrl = "";
          this.scDialogData.thumbnailId = "";
        }
        return;
      }
      this.scDialogData = {
        thumbnailUrl: '',
        isDefense: showDefense ? true : false,
        newImg: '',
        compression: true,
        posterImg: '',
        uploadResponse: '',
        uploadFiles: ''
      }
    },
    getFile(file){
      this.scDialogData.thumbnailUrl = file.tempFile
      this.uploadForm.file = file.raw;
      this.image = file.tempFile;
      // this.uploadForm.imageFileId = file.uid;
    },
    headCallPoster(res){
      this.form.thumbnailId = res.data.file_id;
      this.$message.success(this.$t('table_data.operasucc'))
    },
    handleRemove(isWeb=true){
      if(isWeb)this.showUpload = true;
      if(!isWeb)this.showPhoneUpload = true;
      this.form.thumbnailId = null;
    },
    changeDef(){
      console.log('change',this.scDialogData.compression,this.scDialogData.isDefense)
      if(!this.scDialogData.newImg)return
      this.getBlob()
    },
    uploadSuccess(res,file){
      if(!res)return
      this.scDialogData.newImg = file.tempFile
      // this.form.thumbnailId = res.data.file_id;
      this.$message.success(this.$t('table_data.operasucc'))
      this.scDialogData.uploadResponse = res;
      this.scDialogData.uploadFiles = file.raw;
      this.scDialogData.files = file;
      // if(this.scDialogData.compression){
        // this.getBlob(file)
      // }else if(this.scDialogData.isDefense){
        this.getBlob()
      // }
    },
    delImg(){
      this.scDialogData.thumbnailUrl = ''
      this.scDialogData.newImg = ''
      this.scDialogData.posterImg = ''
      this.scDialogData.uploadResponse = ''
      this.scDialogData.uploadFiles = ''
    },
    removeFile(i){
      this.pngBlob = []
      if(i==1){
        this.$nextTick(()=>{
          this.form.fileId = null
          this.scDialogFileData.imgFiles = []
          this.scDialogFileData.file = null
          this.form.ebookFiles = []
          this.scDialogData.isUploaded=false
          this.ebookLimit = 10000
          // if(this.$refs.scuploadfile.defaultFileList.length){
          //   this.uploadingFiles = this.$refs.scuploadfile.defaultFileList;
          //   this.scDialogFileData.imgFiles = [];
          //   this.pngBlob = []
          //   this.handleEachImg(0)
          // }
        })
      }else{
        this.scDialogFileData.imgPreviewFiles = []
        this.scDialogFileData.previewFile = null
        this.form.previewFiles = []
        this.scDialogFileData.isUploadedFile=false
        this.previewLimit = 10000
      }
      this.uploadingFiles = []
      this.uploadingRes = []
      this.showImg = true
    },
    // 获取本地文件流
    headCallFile(res,file,list){
      console.log('待上传文件列表',list)
      if(res&&res=='OK'&&file){
        console.log('读取成功',res,file,list.length)
        this.uploadFileStatus = true;
        this.uploadingFiles.push(file)
        this.uploadingRes.push(res)

        if(list.length == this.uploadingFiles.length){
          if(!this.scDialogFileData.isPreview)this.ebookLimit = 1
          if(this.scDialogFileData.isPreview)this.previewLimit = 1
          this.scDialogFileData.uploadFiles = file;
          this.handleEachImg(0)
        }
      }
      // this.form.fileId = res.data.file_id
      // this.$message.success(this.$t('table_data.operasucc'))
    },
    // 上传除ebook外其他文件
    headCallOtherFile(res,file,list){
      console.log('待上传文件列表other',res,file,list)
      if(res&&res=='OK'&&file){
        this.uploadFiles(file.raw,-1)
      }
    },
    // 逐张图片解析
    handleEachImg(index){
      let file = this.uploadingFiles[index];
      if(['jpg','jpeg','png','gif','webp','tiff','bmp','svg'].includes(file.raw.type.split('/')[1])){
        this.showImg = true
        this.handlePNG(file.raw,index)
      }else {
        this.showImg = false
        this.handlePDF()
      }
    },
    closeUploadPage(){
      // if(this.uploadFileStatus){
      //   this.$alert(this.$t('artwork_data.uploading'), this.$t('user.title'), {
      //     callback: action => {
      //       this.showFileDialog = false
      //       this.removeFile(this.scDialogFileData.isPreview?0:1)
      //     }
      //   });
      // }else{
        this.openUploadFile()
      // }
    },
    // 显示弹窗
    openUploadFile(isPreview){
      this.showFileDialog = !this.showFileDialog
      if(!this.showFileDialog)return
      this.uploadingNum = 1;
      this.pngBlob = [];
      this.scDialogFileData.isPreview = isPreview=='preview'?true:false
      this.scDialogFileData.compression = true
      if(isPreview == 'file'){
        if(!this.scDialogData.isUploaded&&!this.form.fileId||!this.form.ebookFiles||!this.form.ebookFiles.length){
          this.removeFile(1)
        }else{
          if(this.form.ebookFiles&&this.form.ebookFiles.length){
            this.scDialogFileData.file = 'ebookFile.pdf'
            this.scDialogData.isUploaded = true;
            if(this.form.ebookFiles[0].includes('http')){
              this.scDialogFileData.imgFiles=this.form.ebookFiles&&this.form.ebookFiles.map(n=>({img: n}))
              this.showImg=true
            }else{
              this.showImg = this.scDialogFileData.imgFiles[0].img=='pdf'?false:true
            }
          }
        }
      }else{
        
        if(!this.scDialogFileData.isUploadedFile&&!this.form.previewFiles||!this.form.previewFiles||!this.form.previewFiles.length){
          this.removeFile(0)
        }else{
          if(this.form.previewFiles&&this.form.previewFiles.length){
            this.scDialogFileData.previewFile = 'previewFile.pdf'
            this.scDialogFileData.isUploadedFile = true;
            if(this.form.previewFiles[0].includes('http')){
              this.scDialogFileData.imgPreviewFiles=this.form.previewFiles&&this.form.previewFiles.map(n=>({img: n}))
              this.showImg=true
            }else{
              this.showImg = this.scDialogFileData.imgPreviewFiles[0].img=='pdf'?false:true
            }
          }
        }
      }
    },
  }
}